const forgetPwdToast = Swal.mixin({
    toast: true,
    position: 'center',
    background: '#ffffe1',
    showConfirmButton: false,
    backdrop: false,
    timer: 60000,
    closeButton: true,
});

$(document).ready(function() {
    Tipped.create('#comment-iconof-forgetpwd', "可以通过跟账号绑定的<b>邮箱</b>取回自己的账号。", {skin:'red'});
});

function forgetPwdOnSendCodeClick(target) {
    var email = $('#user-input-content').val();

    if (validateEmail(email)) {
        $.ajax({
            type: 'post',
            async: true,
            data: {"email": email, "type": 2},
            url: document.location.origin + '/api/mailsendtofindpassword',
            dataType: 'text',
            error: function() {

            },
            success: function(data) {
                var json = JSON.parse(data);

                if (json.result == 200) {
                    forgetPwdToast.fire({
                        type: 'success',
                        title: '我们已经给你的邮箱发了邮件，请根据邮件内容找回密码'
                    });
                }
                else {
                    forgetPwdToast.fire({
                        type: 'error',
                        title: json.description
                    });
                }
            }
        });

        $(target).prop('disabled', true);
        $('#user-input-content').prop('disabled', true);
    }
    else {
        forgetPwdToast.fire({
            type: 'error',
            title: '邮箱格式错误，请检查'
        });
    }
}